package com.itheima.action;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.itheima.domain.Customer;
import com.itheima.service.CustomerService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class CustomerAction extends ActionSupport implements ModelDriven<Customer>{
	
	
	private CustomerService service;

	public void setService(CustomerService service) {
		this.service = service;
	}
	
	private Customer customer = new Customer();
	
	
	public Customer getCustomer() {
		return customer;
	}

	@Override
	public Customer getModel() {
		// TODO Auto-generated method stub
		return customer;
	}
	
	private List<Customer> list;
	
	

	public List<Customer> getList() {
		return list;
	}

	//跳转添加页面
	public String add() {
		return "add";
	}
	
	//保存添加
	public String saveAdd() {
		service.saveAdd(customer);
		return "tolist";
	}
	
	//展示客户列表
	public String list() {
		list = service.list();
		ServletActionContext.getRequest().setAttribute("list", list);
		return "list";
	}
	
	//跳转修改页面
	public String edit() {
		customer = service.find(customer);
		return "edit";
	}
	
	//删除客户
	public String delete(){
		service.delete(customer);
		return "tolist";
	}
	
	//模糊查询
	public String likeSerch() {
		list = service.likeSerch(customer);
		return "list";
	}

}
